home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DATATYPE.SWG / 0025_Hunking Routines 2.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  2KB  |  51 lines

  1. {
  2. > Oh, btw Hunking is the conversion of three binary bytes to four ascii
  3. > bytes! Thought you should know that :)
  4.  
  5. Hmmm... so that's 3*8 bits=24 bits, into 4 ascii bytes=6 significant bits, is
  6. 2^6, =64 different ascii characters needed. I think I can manage that...
  7. }
  8. Const
  9.  HunkChars:String[64]=
  10.   'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890:;';
  11.   {         1111111111222222222233333333334444444444555555555566666}
  12.   {1234567890123456789012345678901234567890123456789012345678901234}
  13.  
  14. Function Bin2Hunk(Bin1,Bin2,Bin3: Byte): String;
  15. Var
  16.  Working:LongInt;
  17.  Loop:Byte;
  18.  S:String;
  19. Begin
  20.  Working:=Byte1+Byte2*256+Byte3*65536;
  21.  S:='';
  22.  For Loop:=1 To 4 Do
  23.   Begin
  24.    S:=S+HunkChars[(Working Mod 64)+1];
  25.    Working:=Working Div 64;
  26.   End;
  27.  Bin2Hunk:=S;
  28. End;
  29.  
  30. Procedure Hunk2Bin(Hunk:String; Bin1,Bin2,Bin3:Byte);
  31. Var
  32.  Working:LongInt;
  33. Begin
  34.  Working:=(Pos(Hunk[1],HunkChars)-1)+
  35.           (Pos(Hunk[2],HunkChars)-1)*64+
  36.           (Pos(Hunk[3],HunkChars)-1)*4096+
  37.           (Pos(Hunk[4],HunkChars)-1)*262144;
  38.  Bin1:=Working Mod 256;
  39.  Bin2:=(Working Div 256) Mod 256;
  40.  Bin3:=(Working Div 65536) Mod 256;
  41. End;
  42.  
  43. {
  44. > Those of *course* are not the real outputs, so don't bother trying to
  45. > "un-hunk" them. But if anyone has such functions, thanx before hand!
  46.  
  47. HunkChars must be at least 64 letters long, each being unique. These will be
  48. the characters in the hunk. The result of the function will be the hunk string.
  49. In the un-hunker, the hunk MUST be at least 4 characters long; and only consist
  50. of characters in HunkChars. no checking is done.
  51. }